{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import subprocess\n",
    "from pathlib import Path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "init = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "cmd = 'python3 ../datsrv/capture.py -f 900 -d ../data -a 192.168.1.99'\n",
    "if init:\n",
    "    cmd += ' -i'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_p = Path('../data')\n",
    "for f in data_p.glob('*.sigmf-data'):\n",
    "    f.unlink()\n",
    "for f in data_p.glob('*.sigmf-meta'):\n",
    "    f.unlink()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "STD:  \n",
      "transmission complete ok\n",
      "End\n",
      "\n"
     ]
    }
   ],
   "source": [
    "proc = subprocess.Popen(\n",
    "    cmd,\n",
    "    stdin=None,\n",
    "    stdout = subprocess.PIPE,\n",
    "    stderr = subprocess.PIPE,\n",
    "    shell = True)\n",
    "outinfo, errinfo = proc.communicate()\n",
    "print(\"STD: \",outinfo.decode('utf-8')[-30:])\n",
    "if len(errinfo)>0:\n",
    "    print(\"ERR: \",errinfo.decode('utf-8'))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(\"../ai-sdr\")\n",
    "from Data.opnr import find_data\n",
    "from Data.rawdata import ChannelizedData\n",
    "from LTESync.ltesync import LTESync\n",
    "from LTESync.afc import AFC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "fn = find_data('../data','900.0m')\n",
    "aLTE = ChannelizedData(str(fn))\n",
    "aLTE.channeling(874.2e6,64)\n",
    "aLTE.toDisk()\n",
    "fn_lte = find_data('../data','874.2')\n",
    "aSync = LTESync(str(fn_lte))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 9.625469\n",
      "pss afc cid=2,df=9.625469207763672,pos=1261\n",
      "point  1920000\n",
      "83 (np.float64(26.91532830310996), 92, 0, np.int64(10989), np.int64(1))\n",
      "92 83 0 10989\n"
     ]
    }
   ],
   "source": [
    "aSync.read(end=-1)\n",
    "cid,df,pos,pid = AFC.afc(aSync.waveform,874.2e6)\n",
    "print(cid,df,pos,pid)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.11.3 ('venv': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "160761bc1a904adbbd606c3a9b02244365b1a540f860a2c66cbc5cbd24c54900"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
